package com.hanhai.zrb.backend.web.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;
import com.hanhai.common.web.controller.BaseController;
import com.hanhai.zrb.api.biz.service.PhotoService;
import com.hanhai.zrb.model.photo.Photo;
import com.hanhai.zrb.model.photo.PhotoStatusEnum;
import com.hanhai.zrb.model.photo.PhotoTypeEnum;


@Controller
@RequestMapping("banner")
public class BannerController extends BaseController {
	@Resource
	private PhotoService photoService;
	
	@RequestMapping("index")
	public String index(Model model) {
		return "banner/index";
	}
	
	@RequestMapping("list")
	public void list(Integer page,Integer rows,Model model, HttpServletResponse response) {
		PageInfo pageInfo = photoService.bannerListPage(page, rows);
		this.jsonPage(response, pageInfo);		
	}
	
	@RequestMapping("remove")
	public void remove(@RequestParam Long id, HttpServletResponse response){
		photoService.remove(id);
		this.success(response);
	}
	
	//图片已经保存了，数据库有了记录，只需要更新字段和状态（没有上传图片，不允许创建1条记录）
	@RequestMapping("doadd")
	public void doadd(Photo photo, HttpServletResponse response){
		photo.setStatus(PhotoStatusEnum.NORMAL.getCode());
		photo.setType(PhotoTypeEnum.BANNER.getCode());
		photo.setBizid(-1L);
		photoService.addBanner(photo);
		super.jsonSucceed(response);
	}
	
}